<?php

/**
 * Flickr Photosets - Photoset Page
 * Displays a single photoset.
 * 
 * @author Brad Dougherty <bdougherty@gmail.com>
 * @version 2.0.2
 * @date 10/18/07
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License 3.0
 * @since File available since Release 1.0
 */

/*
Require the function library
This will include all other necessary files
*/
require_once 'lib.php';

/*
Initialize Flickr Photosets and Flickr
*/
$fp = new FlickrPhotosetsCanvas();

// If the user has disabled photosets
if (!$fp->config['enable_gallery_photosets']) {
	$fp->error(FlickrPhotosetsErrors::$photosets_disabled);
}

// Require that we have the set id passed in the url
$fp->require_variables($_GET['sid']);

// Get the photoset and the photos in the set
$photoset = $fp->flickr->photosets_getInfo($_GET['sid']);
$photos = $fp->flickr->photosets_getPhotos($photoset['id']);

// Make sure the NSID matches that of the photoset
if ($fp->nsid != $photoset['owner']) {
	$fp->facebook->redirect($fp->app_url.'/photos/'.$fp->uid.'/sets/');
}

// Remove photos that do not match the privacy settings
$photos['photo'] = $fp->remove_photos($photos['photo']);

// Get the total number of photos
$photo_count = count($photos['photo']);

// Get page information
$page_count = ceil($photo_count / $fp->photos_per_page);
$first_photo = 1 + ($fp->photos_per_page * ($fp->page - 1));
$last_photo = $first_photo + ($fp->photos_per_page - 1);
$last_photo = ($last_photo > $photo_count) ? $photo_count : $last_photo;

// Slice the array to fit the page
$photos['photo'] = array_slice($photos['photo'], $first_photo-1, $fp->photos_per_page);

// Figure out the page that this set is on
$photosets = $fp->flickr->photosets_getList($fp->nsid);
$key = $fp->multi_array_search($photoset['id'], $photosets['photoset']);
$photosets_page = ceil(($key[0] + 1) / $fp->sets_per_page);

?>

<fb:title><?=$fp->get_name(true)?> Photosets | <?=$photoset['title']?></fb:title>

<?=$fp->print_media_header($photoset['title'])?>

<div class="bar clearfix summary_bar">
	<?php $fp->pager($page_count); ?>
	<div class="summary">
		<h4>
			<?php if ($photo_count > 0) { ?>
				Showing <?=$first_photo?> to <?=$last_photo?> of <?=$photo_count?> photos
				<span class="pipe">|</span>
			<?php } ?>
			<a href="<?=$fp->app_url?>/photos/<?=$fp->uid?>/sets/page/<?=$photosets_page?>/">Back to <?=$fp->get_name()?> Flickr Photosets</a>
		</h4>
	</div>
</div>

<?php if ($photo_count > 0) { ?>
<div class="album">
	<table border="0" cellspacing="0">
		<tr>
			<?php
			$i = 0;
			foreach($photos['photo'] as $photo) {
				echo '<td><a href="'.$fp->app_url.'/photos/'.$fp->uid.'/'.$photo['id'].'/in/set-'.$photoset['id'].'/"><img src="'.$fp->flickr->buildPhotoUrl($photo, "thumbnail").'" alt="'.$photo['title'].'" title="'.$photo['title'].'" /></a></td>';
				$i++;
				if ($i > 4) {
					echo '</tr><tr>';
					$i = 0;
				}
			}
			?>
		</tr>
	</table>	
</div>
<?php 
}
else {
	$fp->error(FlickrPhotosetsErrors::$photosets_no_photos);
}
?>

<?php if ($photo_count > 0) { ?>
	<div class="footer">

		<div class="bar clearfix footer_bar">
			<?php $fp->pager($page_count); ?>
		</div>

		<div class="right">
			<fb:share-button class="meta">
				<meta name="title" content="Flickr Photoset: <?=$photoset['title']?>" />
				<meta name="description" content="<?=htmlentities($photoset['description'])?>" />
				<link rel="image_src" href="<?=$fp->flickr->buildPhotoUrl($fp->flickr->photos_getInfo($photoset['primary']), 'thumbnail')?>" />
				<link rel="target_url" href="<?=$fp->app_url?>/photos/<?=$fp->uid?>/sets/<?=$photoset['id']?>/" />
			</fb:share-button>

			<div class="photoactions">
				<a href="<?=$fp->flickr->urls_getUserPhotos($fp->nsid)?>sets/<?=$photoset['id']?>/">Flickr Photoset Page</a>
				<a href="<?=$fp->flickr->urls_getUserPhotos($fp->nsid)?>sets/<?=$photoset['id']?>/comments/">Flickr Comments</a>
				<a href="<?=$fp->flickr->urls_getUserPhotos($fp->nsid)?>sets/<?=$photoset['id']?>/map/">Flickr Map</a>
				<a href="<?=$fp->flickr->urls_getUserPhotos($fp->nsid)?>sets/<?=$photoset['id']?>/show/">Flickr Slideshow</a>
			</div>
		</div>

		<div class="photoinfo">
			<p>See: <a href="<?=$fp->app_url?>/photos/<?=$fp->uid?>/sets/<?=$photoset['id']?>/map/">Map</a> | <a href="<?=$fp->app_url?>/photos/<?=$fp->uid?>/sets/<?=$photoset['id']?>/show/">Slideshow</a></p>

			<p><?=$photoset['description']?></p>
		</div>

		<div class="photocomment">

			<?=$fp->print_comments($fp->flickr->photosets_comments_getList($photoset['id']))?>

		</div>

	</div>
<?php } ?>

<div class="clearfix"></div>

<?=$fp->echo_footer(true)?>